package org.infinitest.intellij.idea.facet;

import com.intellij.facet.Facet;
import com.intellij.facet.FacetType;
import com.intellij.facet.FacetTypeId;
import com.intellij.openapi.module.Module;
import org.infinitest.intellij.idea.window.InfinitestToolWindowComponent;
import org.jetbrains.annotations.NotNull;

public class InfinitestFacet extends Facet<InfinitestFacetConfiguration>
{
  public static FacetTypeId<InfinitestFacet> ID = new FacetTypeId<InfinitestFacet>();
  private Module module;

  public InfinitestFacet(@NotNull FacetType facetType, @NotNull Module module, String name,
    @NotNull InfinitestFacetConfiguration configuration, Facet underlyingFacet)
  {
    super(facetType, module, name, configuration, underlyingFacet);
    this.module = module;
  }

  public void initFacet()
  {
    getWindow().facetInitialized();
  }

  public void disposeFacet()
  {
    super.disposeFacet();
    getWindow().facetDisposed();
  }

  private FacetListener getWindow()
  {
    return module.getComponent(InfinitestToolWindowComponent.class);
  }
}
